﻿// JScript File

function comptime(beginTime,endTime)
{ 

    if(beginTime  == "" || endTime == "")
        return  0;
     
    var delimitChar=/[\-\/\s]/g;
    var beginTimes=beginTime.split(delimitChar); 
    var endTimes=endTime.split(delimitChar); 
     
    var beginDates = beginTimes[2].split(' ');
    var endDates   = endTimes[2].split(' ');
    
    
    beginTimes[2] = beginDates[0];
    endTimes[2]   = endDates[0];

    beginTime=beginTimes[1]+'-'+beginTimes[2]+'-'+beginTimes[0]+' '+beginTime.substring(10,19); 
    endTime=endTimes[1]+'-'+endTimes[2]+'-'+endTimes[0]+' '+endTime.substring(10,19); 
   
   
    
    var a =(Date.parse(endTime)-Date.parse(beginTime))/3600/1000; 

    

    if(a<0)
    { 
        return -1; 
    }
    else if (a>0)
    { 
        return 1; 
    }else if (a==0)
    { 
        return 0; 
    }else
    { 
        return 'exception' 
    } 
}

    function ChkDateTime(val, args) 
       { 
            var check= /^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]((((0?[13578])|(1[02]))[\-\/\s]((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]((((0?[13578])|(1[02]))[\-\/\s]((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[0-9])|(1[0-9])|(2[0-3]))\:(([0-5][0-9])|([0-9]))((\s)|(\:(([0-5][0-9])|([0-9]))))))?$/;
 
            if( val.id.indexOf("To") >= 0 || val.id.indexOf("From") >= 0)
            {
            
                var TextName  = val.id.replace("validate", "txt");
                
                var FromText  = TextName.replace("To", "From");
                
                var ToText    = TextName.replace("From", "To");
                
               
                           
                var fromElement = document.getElementById(FromText);
                
                
                var toElement = document.getElementById(ToText);

                //如果是空值，则也允许输入
                if(fromElement.value=="" || toElement.value=="")
                {
                    
                   //检测值
                   if (!check.exec(args.Value)) 
                   {  
                      args.IsValid = false; 
                      return;
                   }
                   
                   args.IsValid = true;
                   return;                     
                       
                 }
            }
            
            
            if (!check.exec(args.Value)) 
            {
              args.IsValid = false;
            }
            
            else
            {
                
              args.IsValid = true;
            }
        }
        
        function ChkDateTime1(val, args) 
       { 
            var check= /^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]((((0?[13578])|(1[02]))[\-\/\s]((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]((((0?[13578])|(1[02]))[\-\/\s]((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[0-9])|(1[0-9])|(2[0-3]))\:(([0-5][0-9])|([0-9]))((\s)|(\:(([0-5][0-9])|([0-9]))))))?$/;
 
            if( val.id.indexOf("To") >= 0 || val.id.indexOf("From") >= 0)
            {
            
                var TextName  = val.id.replace("validate", "txt");

                var ToText    = TextName.replace("From1", "To");
                
                var FromText  = TextName.replace("From1", "From");

                
               
                           
                var fromElement = document.getElementById(FromText);
                
                
                var toElement = document.getElementById(ToText);

                //如果是空值，则也允许输入
                if(fromElement.value=="" || toElement.value=="")
                {
                       args.IsValid = true;
                       return;
                 }
                 
                 if (!check.exec(args.Value)) 
                {
                    //之前已经检测，不需要重复检测
                    args.IsValid = true;
                    return;
                }
                
                //只有当所有的值都满足要求时，才进行开始时间要小于等于结束时间的检测
                if (check.exec(toElement.value) && check.exec(fromElement.value))
                {
                    if (val.id.indexOf("From") >= 0)
                    {
                        //开始和结束时间，只在开始时间上检测一次
                        if( comptime(  fromElement.value , toElement.value) < 0 )
                        {
                          args.IsValid = false; 
                          return;
                        }
                    }
                }
            }
        }


